#include <osal/osal.h>
#include <basic_types.h>

#include <api/libc/alloc.h>
#include <api/libc/printf.h>
#include <api/libc/string.h>

#include <hld/hld_dev.h>
#include <hld/sdec/sdec.h>
#include <hld/sdec/sdec_dev.h>
#include <hld/osd/osddrv.h>
#include <api/libsubt/subt_osd.h>


#include "sdec_buffer.h"
#include "sdec_m3327.h"


extern UINT32 stc_delay;
struct sdec_m3327_private * g_sdec_priv;
OSAL_ID sdec_tsk_id;
OSAL_ID sdec_flag_id;
OSAL_ID	sdec_alarm_id = OSAL_INVALID_ID;
UINT8  sdec_tsk_qtm;
UINT8  sdec_tsk_pri;	

UINT16 rle_len;
UINT8 *rle_buf;
UINT8 cnt4bit = 0;
UINT8 cnt2bit = 0;

UINT8 *subt_data_buff = NULL;
UINT16 subt_data_buff_len = 0;


UINT32 sdec_temp_size;
UINT8 *sdec_temp_buf;
UINT32 sdec_temp_buf_len; 

UINT32 sdec_temp_size2;

UINT16 g_composition_page_id ;
UINT16 g_ancillary_page_id ;

struct SDecDataHdr *sdec_bs_hdr_buf;

struct SDecDataHdr pSDecInitHdr;
struct SDecDataHdr *pSDecWrHdr;
struct SDecDataHdr *pSDecRdHdr;


UINT8 page_released;
UINT8 page_finished;

BOOL subt_show_on;

//UINT8* sdec_pixel_buf;
//UINT32 sdec_pixel_buf_len;
UINT8 subt_transparent_color; 


struct PageCB g_page_cb;
struct RegionCB g_region_cb[MAX_REGION_IN_PAGE];

UINT8 g_region_idx;

UINT8 identifier_detected;
UINT8 sdec_stuffing_flag;
UINT32	uSDecRemainSize;
UINT8*	puSDecStartPoint ;
UINT8	sdec_flag_not_enough_data;


UINT8 subt_clut[MAX_REGION_IN_PAGE][MAX_ENTRY_IN_CLUT][4];
UINT8 subt_clut_id[MAX_REGION_IN_PAGE];

const UINT8 subt_defalt_clut[MAX_ENTRY_IN_CLUT][4] = 
{
	{0x00,0x00,0x00,0xff},{0x10,0x80,0x80,0x00},{0xeb,0x80,0x80,0x00},{0x10,0x80,0x80,0x00},
	{0xeb,0x80,0x80,0x00},{0x10,0x80,0x80,0x00},{0xeb,0x80,0x80,0x00},{0x10,0x80,0x80,0x00},
	{0xeb,0x80,0x80,0x00},{0x10,0x80,0x80,0x00},{0xeb,0x80,0x80,0x00},{0x10,0x80,0x80,0x00},
	{0xeb,0x80,0x80,0x00},{0x10,0x80,0x80,0x00},{0xeb,0x80,0x80,0x00},{0xdc,0x80,0x80,0xff}
};
UINT32 sdec_get_clut = 0;
static BOOL sdec_stopped = FALSE;//get sdec status
static BOOL sdec_clear_page = FALSE;

BOOL get_sdec_status()
{
    return sdec_stopped;
}

void set_sdec_clear_page(BOOL clear)
{
    sdec_clear_page = clear;
}

__ATTRIBUTE_RAM_
void sdec_add_to_temp(UINT8 *pData,UINT32 Size)
{
	UINT32 i;
	//SDEC_PRINTF("2. pData = %8x, Size = %d\n",pData,Size);
	if(sdec_temp_size+Size >sdec_temp_buf_len)
	{
		SDEC_PRINTF("%s : Error: exceptional temp data size!\n",__FUNCTION__);
		return;
	}
	for(i=0;i<Size;i++)
		sdec_temp_buf[sdec_temp_size+i]=*pData++;
	sdec_temp_size += Size;
}

__ATTRIBUTE_RAM_
void sdec_copy_to_temp(UINT8 *pData,UINT32 Size)
{
	UINT32 i;
	if(Size >sdec_temp_buf_len-184)
	{
		SDEC_PRINTF("%s : Error: exceptional temp data size!\n",__FUNCTION__);
		return;
	}
	for(i=0;i<Size;i++)
		sdec_temp_buf[i]=*pData++;
	sdec_temp_size = Size;
}

__ATTRIBUTE_RAM_
UINT8 getnext2bit()
{

	UINT8 mychar;
	UINT8 my2bit;

	if(rle_len==0)
		return 0xff; //

	if(cnt2bit == 0)
	{
		rle_buf++;
		rle_len--;
		mychar = *rle_buf;
		my2bit = mychar >> 6;
		cnt2bit++;
	}
	else if(cnt2bit == 3)
	{
		//mychar = *rle_buf++;
		//rle_len--;
		mychar = *rle_buf;
		my2bit = (mychar&0x03);
		cnt2bit = 0;
	}
	else
	{
		mychar = *rle_buf;
//		my2bit = (mychar&(0xc0>>(2*cnt2bit))) >> (6-2*cnt2bit);
		my2bit = (mychar&(0xc0>>(cnt2bit<<1))) >> (6-(cnt2bit<<1));
		cnt2bit++;
	}

	return my2bit;
}
__ATTRIBUTE_RAM_
UINT8 getnext4bit()
{

	UINT8 mychar;
	UINT8 my4bit=0;

	if(rle_len==0 && cnt4bit == 0)
		return 0xff; //

	if(cnt4bit == 0)
	{
		++rle_buf;
		mychar = *rle_buf;
		rle_len--;
//		my4bit = (mychar&(0xf0>>(4*cnt4bit))) >> (4-4*cnt4bit);
		my4bit = (mychar >> 4);
		cnt4bit++;
	}
	else if(cnt4bit == 1)
	{
		mychar = *rle_buf;
//		my4bit = (mychar&(0xf0>>(4*cnt4bit))) >> (4-4*cnt4bit);
		my4bit = (mychar&0x0F);
		cnt4bit = 0;
	}

	return my4bit;
}

__ATTRIBUTE_RAM_
UINT16 getnext8bit()
{
	UINT16 my8bit;

	if(rle_len==0)
		return 0xffff;

	my8bit = *++rle_buf;
	rle_len--;

	return my8bit;
}

void sdec_m3327_software_init()
{
	INT32 	i,j;

	pSDecInitHdr.uDataSize = 0;
	pSDecRdHdr = &pSDecInitHdr;
	pSDecWrHdr = &pSDecInitHdr;

	sdec_get_clut = 0;

	sdec_temp_size = 0;
	sdec_temp_size2 = 0;

	page_released = 1;
	page_finished = 0;
	g_region_idx = 0;//20050927 tom

    g_page_cb.clut_cnt = 0;
	g_page_cb.region_cnt = 0;
	for(i=0;i<MAX_REGION_IN_PAGE;i++)
	{
		g_page_cb.region_id[i]=0xff;
		g_page_cb.end_of_display = 1;
	}
	for(i=0;i<MAX_REGION_IN_PAGE;i++)
	{
		g_region_cb[i].object_cnt = 0;
		g_region_cb[i].region_id = 0xff;
		g_region_cb[i].region_width = 0;
		g_region_cb[i].region_height = 0;
		for(j=0;j<MAX_OBJECT_IN_REGION;j++)
			g_region_cb[i].object_id[j] = 0xffff;
		//g_region_cb[i].data = sdec_pixel_buf;
	}

    g_page_cb.display_width = 0;
    g_page_cb.display_height = 0;

	//Initialize subt_clut to transparent to fix "green block" issue
	//--Michael 2006/05/12
	//guoping 2009-01-21, for some stream have no clut data
	for(i = 0; i < MAX_REGION_IN_PAGE; i++)
	{
		for(j=0;j<MAX_ENTRY_IN_CLUT;j++)
			subt_clut[i][j][3] = (15<<4);
		//MEMCPY(subt_clut[i], subt_defalt_clut, sizeof(subt_defalt_clut));
	}
  
	//MEMSET(sdec_pixel_buf, subt_transparent_color, sdec_pixel_buf_len);

	identifier_detected=0;
	sdec_stuffing_flag = 0;
	sdec_flag_not_enough_data = 0;

	sdec_sbf_create();
	sdec_hdr_buf_create();

	SDEC_PRINTF("%s : initialize sdec!\n",__FUNCTION__);
	//osd_subt_enter();
}

void SDec_Task(UINT32 param1,UINT32 param2)
{

	OSAL_ER result;
	UINT32 flgptn ;
	UINT32 stc_msb32;

	struct sdec_m3327_private*priv=(struct sdec_m3327_private*)(((struct sdec_device*)param1)->priv);

	UINT32 i;
	UINT32 start_tick = 0;
	UINT32 end_tick = 0;

	while(1) // run forever when task exist.
	{
		if(priv->status == SDEC_STATE_IDLE)
		{
			result = osal_flag_wait(&flgptn,sdec_flag_id, SDEC_CMD_START|SDEC_CMD_SHOWON|SDEC_CMD_SHOWOFF, OSAL_TWF_ORW, OSAL_WAIT_FOREVER_TIME);
			if(flgptn&SDEC_CMD_START)
			{
				SDEC_PRINTF("%s : SDEC start!\n",__FUNCTION__);
				osal_flag_clear(sdec_flag_id, SDEC_CMD_START);
				sdec_m3327_software_init();
				osal_flag_set(sdec_flag_id,SDEC_MSG_START_OK);
				priv->status = SDEC_STATE_PLAY;

			}
			if(flgptn&SDEC_CMD_SHOWON)
			{
				SDEC_PRINTF("%s : SDEC start show!\n",__FUNCTION__);
				osal_flag_clear(sdec_flag_id, SDEC_CMD_SHOWON);
				subt_show_on = TRUE;
				osd_subt_enter();
				osal_flag_set(sdec_flag_id,SDEC_MSG_SHOWON_OK);

			}
			if(flgptn&SDEC_CMD_SHOWOFF)
			{
				SDEC_PRINTF("%s : SDEC hide!\n",__FUNCTION__);
				osal_flag_clear(sdec_flag_id, SDEC_CMD_SHOWOFF);
				subt_show_on = FALSE;
				osd_subt_leave();
				osal_flag_set(sdec_flag_id,SDEC_MSG_SHOWOFF_OK);

			}
		}
		else if(priv->status == SDEC_STATE_PLAY)
		{
			result = osal_flag_wait(&flgptn,sdec_flag_id, SDEC_CMD_STOP|SDEC_CMD_SHOWON|SDEC_CMD_SHOWOFF|SDEC_MSG_DATA_AVAILABLE|SDEC_MSG_BUFF_AVAILABLE, OSAL_TWF_ORW, 100);
			 if(sdec_clear_page)
			{
				//libc_printf("\nclear page");
				SDEC_PRINTF("%s : SDEC clear page!\n",__FUNCTION__);
                     	osd_subt_clear_page();
                     	set_sdec_clear_page(FALSE);
			}
			if(OSAL_E_TIMEOUT==result)
			{
			         //SDEC_PRINTF("Wait update flag time out!\n");
			         if(priv->display_entry_cb)
					 priv->display_entry_cb(0);
				  //display_entry();
			         continue;
			}

			if(flgptn&SDEC_CMD_STOP)
			{
				SDEC_PRINTF("%s : SDEC stop!\n",__FUNCTION__);
				osal_flag_clear(sdec_flag_id, SDEC_CMD_STOP|SDEC_CMD_START|SDEC_MSG_DATA_AVAILABLE|SDEC_MSG_BUFF_AVAILABLE);
				//osal_flag_clear(sdec_flag_id, SDEC_CMD_STOP);
				//osd_subt_leave();
				osal_flag_set(sdec_flag_id,SDEC_MSG_STOP_OK);
				priv->status = SDEC_STATE_IDLE;

				continue;
			}
			if(flgptn&SDEC_CMD_SHOWON)
			{
				SDEC_PRINTF("%s : SDEC show!\n",__FUNCTION__);
				osal_flag_clear(sdec_flag_id, SDEC_CMD_SHOWON);
				subt_show_on = TRUE;
				osd_subt_enter();
				osal_flag_set(sdec_flag_id,SDEC_MSG_SHOWON_OK);

			}
			if(flgptn&SDEC_CMD_SHOWOFF)
			{
				SDEC_PRINTF("%s : SDEC hide!\n",__FUNCTION__);
				osal_flag_clear(sdec_flag_id, SDEC_CMD_SHOWOFF);
				subt_show_on = FALSE;
				osd_subt_leave();
				osal_flag_set(sdec_flag_id,SDEC_MSG_SHOWOFF_OK);

			}
			if(flgptn&SDEC_MSG_DATA_AVAILABLE)
			{
				//SDEC_PRINTF("update flag received!\n");
				osal_flag_clear(sdec_flag_id, SDEC_MSG_DATA_AVAILABLE);
				if(priv->stream_parse_cb)
					priv->stream_parse_cb();
				//stream_parse();
				 if(priv->display_entry_cb)
					 priv->display_entry_cb(1);
				//display_entry();
			}
			if(flgptn&SDEC_MSG_BUFF_AVAILABLE)
			{
				//SDEC_PRINTF("release flag received!\n");
				osal_flag_clear(sdec_flag_id, SDEC_MSG_BUFF_AVAILABLE);
				if(priv->stream_parse_cb)
					priv->stream_parse_cb();
				//stream_parse();
				 if(priv->display_entry_cb)
					 priv->display_entry_cb(2);
				//display_entry();
			}
		}
	}

}

__ATTRIBUTE_REUSE_
INT32  sdec_m3327_open(struct sdec_device *dev)
{

	OSAL_T_CTSK t_ctsk;
	OSAL_T_CMBF t_cmbf;
	struct sdec_m3327_private * priv = (struct sdec_m3327_private*)(dev->priv) ;

	subt_show_on = TRUE;
	priv->status = SDEC_STATE_IDLE;

	sdec_flag_id=osal_flag_create(0x00000000);
	if(OSAL_INVALID_ID==sdec_flag_id)
	{
	    SDEC_PRINTF("%s : Error: Create flag of sdec  failed!\n",__FUNCTION__);
	    return RET_FAILURE;
	}
	t_ctsk.task = (FP)SDec_Task;
	t_ctsk.para1 = (UINT32)dev;
	t_ctsk.para2 = 0;
	t_ctsk.stksz = 0x1000;
	t_ctsk.quantum = sdec_tsk_qtm;
    	t_ctsk.itskpri = sdec_tsk_pri;
	sdec_tsk_id = osal_task_create(&t_ctsk);
	if(OSAL_INVALID_ID==sdec_tsk_id)
	{
        SDEC_PRINTF("%s : Error: Can not create SDECDec_Task!\n",__FUNCTION__);
		return RET_FAILURE;
	}

	SDEC_PRINTF("%s : sdec_m3327 open SUCCESS!\n",__FUNCTION__);

	return RET_SUCCESS;

}

INT32  sdec_m3327_close(struct sdec_device *dev)
{
	struct sdec_m3327_private * priv = (struct sdec_m3327_private*)(dev->priv) ;
	if(OSAL_E_OK!=osal_task_delete(sdec_tsk_id))
	{
		SDEC_PRINTF("%s : Error: fail to delete task!\n",__FUNCTION__);
		return RET_FAILURE;
	}

	if(OSAL_E_OK!=osal_flag_delete(sdec_flag_id))
	{
		SDEC_PRINTF("%s : Error: fail to delete flag!\n",__FUNCTION__);
		return RET_FAILURE;
	}

	return RET_SUCCESS;
}

INT32  sdec_m3327_start(struct sdec_device *dev,UINT16 composition_page_id,UINT16 ancillary_page_id)
{
	struct sdec_m3327_private * priv = (struct sdec_m3327_private*)(dev->priv) ;
	UINT32 flgptn ;
	OSAL_ER result;

	if(priv->status == SDEC_STATE_IDLE)
	{
		SDEC_PRINTF("%s : User start sdec!\n",__FUNCTION__);
		
		g_composition_page_id = composition_page_id;
		g_ancillary_page_id = ancillary_page_id;
		osal_flag_set(sdec_flag_id, SDEC_CMD_START);
		flgptn = 0;
		result = osal_flag_wait(&flgptn,sdec_flag_id, SDEC_MSG_START_OK, OSAL_TWF_ORW, OSAL_WAIT_FOREVER_TIME);
		if(OSAL_E_OK!=result)
		{
		         SDEC_PRINTF("%s : Error: Wait SDEC_MSG_START_OK failed with err code %s\n",
		         __FUNCTION__, result == OSAL_E_TIMEOUT?"OSAL_E_TIMEOUT":"OSAL_E_FAIL");
		         return !RET_SUCCESS;
		}
		osal_flag_clear(sdec_flag_id, SDEC_MSG_START_OK);
	}
    sdec_stopped = FALSE;
	return RET_SUCCESS;
}

INT32  sdec_m3327_stop(struct sdec_device *dev)
{
      struct sdec_m3327_private * priv = (struct sdec_m3327_private*)(dev->priv) ;
      UINT32 flgptn ;
      OSAL_ER result;

	if(priv->status == SDEC_STATE_PLAY)
	{
		SDEC_PRINTF("%s : User stop sdec!\n",__FUNCTION__);
		osal_flag_set(sdec_flag_id, SDEC_CMD_STOP);
		flgptn = 0;
		result = osal_flag_wait(&flgptn,sdec_flag_id, SDEC_MSG_STOP_OK, OSAL_TWF_ORW, OSAL_WAIT_FOREVER_TIME);
		if(OSAL_E_OK!=result)
		{
		         SDEC_PRINTF("%s : Error: Wait SDEC_MSG_START_OK failed with err code %s\n",
		         __FUNCTION__, result == OSAL_E_TIMEOUT?"OSAL_E_TIMEOUT":"OSAL_E_FAIL");
		         return !RET_SUCCESS;
		}
		osal_flag_clear(sdec_flag_id, SDEC_MSG_STOP_OK);

	}
    sdec_stopped = TRUE;
    return RET_SUCCESS;
}


INT32  sdec_m3327_pause(struct sdec_device *dev)
{
      struct sdec_m3327_private * priv = (struct sdec_m3327_private*)(dev->priv) ;
      UINT32 flgptn ;
      OSAL_ER result;

	if(priv->status == SDEC_STATE_PLAY)
	{
		SDEC_PRINTF("%s : User pause sdec!\n",__FUNCTION__);
		osal_flag_set(sdec_flag_id, SDEC_CMD_PAUSE);
		flgptn = 0;
		result = osal_flag_wait(&flgptn,sdec_flag_id, SDEC_MSG_PAUSE_OK, OSAL_TWF_ORW, OSAL_WAIT_FOREVER_TIME);
		if(OSAL_E_OK!=result)
		{
		         SDEC_PRINTF("%s : Error: Wait SDEC_MSG_PAUSE_OK failed with err code %s\n",
		         __FUNCTION__, result == OSAL_E_TIMEOUT?"OSAL_E_TIMEOUT":"OSAL_E_FAIL");
		         return !RET_SUCCESS;
		}
		osal_flag_clear(sdec_flag_id, SDEC_MSG_PAUSE_OK);

	}
       return RET_SUCCESS;
}
INT32  sdec_m3327_showonoff(struct sdec_device *dev,BOOL bOn)
{
      struct sdec_m3327_private * priv = (struct sdec_m3327_private*)(dev->priv) ;
      UINT32 flgptn ;
      OSAL_ER result;

	if(bOn == TRUE)
	{
		osal_flag_set(sdec_flag_id, SDEC_CMD_SHOWON);
		flgptn = 0;
		result = osal_flag_wait(&flgptn,sdec_flag_id, SDEC_MSG_SHOWON_OK, OSAL_TWF_ORW, OSAL_WAIT_FOREVER_TIME);
		if(OSAL_E_OK!=result)
		{
		         SDEC_PRINTF("%s : Error: Wait SDEC_MSG_PAUSE_OK failed with err code %s\n",
		         __FUNCTION__, result == OSAL_E_TIMEOUT?"OSAL_E_TIMEOUT":"OSAL_E_FAIL");
		         return !RET_SUCCESS;
		}
		osal_flag_clear(sdec_flag_id, SDEC_MSG_SHOWON_OK);
	}
	else
	{
		osal_flag_set(sdec_flag_id, SDEC_CMD_SHOWOFF);
		flgptn = 0;
		result = osal_flag_wait(&flgptn,sdec_flag_id, SDEC_MSG_SHOWOFF_OK, OSAL_TWF_ORW, OSAL_WAIT_FOREVER_TIME);
		if(OSAL_E_OK!=result)
		{
		         SDEC_PRINTF("%s : Error: Wait SDEC_MSG_PAUSE_OK failed with err code %s\n",
		         __FUNCTION__, result == OSAL_E_TIMEOUT?"OSAL_E_TIMEOUT":"OSAL_E_FAIL");
		         return !RET_SUCCESS;
		}
		osal_flag_clear(sdec_flag_id, SDEC_MSG_SHOWOFF_OK);
	}
       return RET_SUCCESS;
}
///////////////////////////////////////////////////////////////////////////
extern BOOL g_IsHDVideo;
__ATTRIBUTE_RAM_
INT32 sdec_m3327_request_write(struct sdec_device *dev,UINT32 uSizeRequested,struct control_block* pTDataCtrlBlk,UINT8** ppuData,UINT32* puSizeGot)
{
	UINT32 uReqSize;
	UINT32 uHdrPtr;
	static UINT8 last_stcid=0xff;
	static UINT32 last_pts = 0;

	struct sdec_m3327_private * priv = (struct sdec_m3327_private*)(dev->priv) ;
	if(priv->status == SDEC_STATE_IDLE)
	{
		SDEC_PRINTF("SDEC_STATE_IDLE!\n");
		return RET_STA_ERR;
	}

	if(g_IsHDVideo)
	{
		SDEC_PRINTF("SDEC_HD_ABORT!\n");
		return RET_STA_ERR;
	}

	//uSizeRequested= (uSizeRequested>552)?552:(uSizeRequested);
	uSizeRequested= (uSizeRequested>184)?184:(uSizeRequested);

	uReqSize= uSizeRequested;
	//SDEC_PRINTF("\nD WR REQ(%x):\n",uSizeRequested);
	if(sdec_sbf_wr_req(&uReqSize, ppuData)==RET_FAILURE)
	{
		SDEC_PRINTF("request write FAILURE\n");
		return RET_FAILURE;
	}
	//SDEC_PRINTF("size= %d ,wpt = %x\n",uReqSize,*ppuData);

	if(sdec_hdr_buf_wr_req(&uHdrPtr)==RET_FAILURE)
	{
		SDEC_PRINTF("HDR request write FAILURE\n");
        static struct sdec_device *sdec_dev;
 	    sdec_dev = (struct sdec_device *)dev_get_by_name("SDEC_M3327_0");
        sdec_m3327_stop(sdec_dev);
        sdec_m3327_start(sdec_dev,g_composition_page_id,g_ancillary_page_id);//reset sdec to fix rotate stream's subtitle no show bug
        
		return RET_FAILURE;
	}
	pSDecWrHdr = &sdec_bs_hdr_buf[uHdrPtr];
	pSDecWrHdr->puStartPoint = *ppuData;
	pSDecWrHdr->uDataSize = 0;

	if (NULL == pTDataCtrlBlk)
		pSDecWrHdr->bInfoValid = FALSE;
	else
	{
		pSDecWrHdr->bInfoValid = TRUE;
		pSDecWrHdr->uPesStart = (pTDataCtrlBlk->data_continue == 0x00)?0x01:0x00;
		//pSDecWrHdr->uCtrlByte = pTDataCtrlBlk->uCtrlByte;

		if(pTDataCtrlBlk->pts_valid == 1)
		{
			last_stcid = pTDataCtrlBlk->stc_id;
			last_pts = pTDataCtrlBlk->pts;
		}
		pSDecWrHdr->uStcId = last_stcid;
		pSDecWrHdr->uPTS = last_pts;
	}

	pTDataCtrlBlk->instant_update = 1;

	*puSizeGot = (uReqSize>uSizeRequested? uSizeRequested : uReqSize);
	return RET_SUCCESS;

}
__ATTRIBUTE_RAM_
void sdec_m3327_update_write(struct sdec_device *dev,UINT32 uSize)
{
       UINT32 stc_msb32;
	struct sdec_m3327_private * priv = (struct sdec_m3327_private*)(dev->priv) ;
	if(priv->status == SDEC_STATE_IDLE)
	{
		SDEC_PRINTF("SDEC_STATE_IDLE!\n");
		return ;
	}

	if(g_IsHDVideo)
	{
		SDEC_PRINTF("SDEC_HD_ABORT!\n");
		return;
	}

	if(pSDecWrHdr==NULL)return;
	if(!uSize)return ;

	//SDEC_PRINTF("D WR UPD:\n");
	 sdec_sbf_wr_update(uSize);

	//SDEC_PRINTF("wr upd = %d\n",uSize);

	pSDecWrHdr->uDataSize += uSize;

	sdec_hdr_buf_wr_update();
	osal_flag_set(sdec_flag_id,SDEC_MSG_DATA_AVAILABLE);


	//SDEC_PRINTF("UPD_STC=%8x, uPTS= %8x\n",stc_msb32,pSDecWrHdr->uPTS);

	return ;
}
///////////////////////////////////////////////////////////////////////////






